﻿/*标记地图模块化*/
/*步行*/

var ISS_Map_walk = {
    //公交线路查询
    WalkLine: function (station, station2, startname, endname) {
        //公交查询
        this.selectMapPoint = function () {
            var transit = new BMap.WalkingRoute(ISS_MAP.nearByMap, { renderOptions: { map: ISS_MAP.nearByMap, panel: "r-result", autoViewport: true} });
            transit.search(station, station2);
            var searchResult = true;

            jQuery("#pickresult").html('');  //先清空历史记录
            ISS_MAP.ClearArc();  //清除所有覆盖物

            transit.setSearchCompleteCallback(function (results) {
                if (transit.getStatus() == BMAP_STATUS_SUCCESS) {
                    //最少时间
                    var t_result = [];
                    if (results.getNumPlans() > 0) {

                        // 获取第一条方案
                        var plan = results.getPlan(0);
                        // 获取方案的行走线路
                        var route = plan.getRoute(0);

                        // 获取每个关键步骤,并输出到页面
                        var s = [];
                        s.push("<div class=\"search-info\">约" + plan.getDistance(true) + "/" + plan.getDuration(true) + "</div>");
                        s.push("<div class=\"search-result\" id=\"walk_Result\">");
                        s.push("<h5><a href=\"#\"><p><i class=\"ico-start\"></i>起点:" + startname + "</p></a></h5>");
                        for (var index = 0; index < route.getNumSteps(); index++) {
                            var step = route.getStep(index)
                            s.push("<dl>");
                            s.push("<dt><i>" + parseInt(index + 1) + ".</i>" + step.getDescription() + "</dt><dd></dd>");
                            s.push("</dl>");
                        }
                        s.push("<h5><a href=\"#\"><p><i class=\"ico-end\"></i>终点:" + endname + "</p></a></h5>");
                        s.push("</div>");
                        jQuery("#pickresult").html(s.join(""));
                    } else {
                        jQuery("#pickresult").css("display", "block");
                        jQuery("#pickresult").html("<div class=\'search-info\'>未找到相关步行信息</div>"); //步行查询提示
                        searchResult = false;
                    }
                }
                else {
                    jQuery("#pickresult").css("display", "block");
                    jQuery("#pickresult").html("<div class=\'search-info\'>未找到相关步行信息</div>"); //步行查询提示
                    searchResult = false;
                }
                //显示结果
                setTimeout(
                    function () { ISS_MAP.PickModal(searchResult); },
                    1000);
            });
        }
    },
    //公交搜索结果tab切换
    SearchWalkTab: function () {
        //定义起始点
        var startpoint;
        var endpoint;
        if (ISS_MAP_SEARCH_START.Lng && ISS_MAP_SEARCH_START.Lng != ''
        && ISS_MAP_SEARCH_START.Lat && ISS_MAP_SEARCH_START.Lat != '') {
            startpoint = new BMap.Point(ISS_MAP_SEARCH_START.Lng, ISS_MAP_SEARCH_START.Lat);
        } else {
            startpoint = ISS_MAP_SEARCH_START.Name;
        }
        if (ISS_MAP_SEARCH_END.Lng && ISS_MAP_SEARCH_END.Lng != ''
        && ISS_MAP_SEARCH_END.Lat && ISS_MAP_SEARCH_END.Lat != '') {
            endpoint = new BMap.Point(ISS_MAP_SEARCH_END.Lng, ISS_MAP_SEARCH_END.Lat);
        } else {
            endpoint = ISS_MAP_SEARCH_END.Name;
        }
        var walkline = new ISS_Map_walk.WalkLine(startpoint, endpoint, ISS_MAP_SEARCH_START.Name, ISS_MAP_SEARCH_END.Name);
        walkline.selectMapPoint();
    }
}